package com.java.day13.puke;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class PukeCardUtils {

    // 声明扑克点数的数组
    public static final String[] POINTS_ARR = {"3","4","5","6","7","8","9","10","J","Q","K","A","2","SJOKER","BJOKER"};

    // 声明扑克花色的数组
    public static final String[] PUKE_TYPE = {"♥","♠","♦","♣"};


    /**
     * 模拟斗地主抓牌
     * @param cards  54张牌
     * @param p1  玩家1的手牌
     * @param p2
     * @param p3
     * @param d1  底牌，剩三张
     */
    public static void drawPukeCard(List<PukeCard> cards,List<PukeCard> p1,List<PukeCard> p2,
                                    List<PukeCard> p3,List<PukeCard> d1){
        //打乱
        Collections.shuffle(cards);
//        System.out.println(cards);
        for (int i = 3; i < cards.size(); i+=3) {

            p1.add(cards.get(i-2));
            p2.add(cards.get(i-1));
            p3.add(cards.get(i));
            if(i>cards.size()-4){
                d1.add(cards.get(i));
                d1.add(cards.get(i+1));
                d1.add(cards.get(i+2));
                break;
            }

        }

        

    }

    /**
     * 创建一副扑克牌
     * @return
     */
    public static List<PukeCard> createPukeList(){

        ArrayList<PukeCard> pukeCards = new ArrayList<>();

        for (int i = 0; i < POINTS_ARR.length-2; i++) {
            for (String type : PUKE_TYPE) {
                PukeCard pukeCard = new PukeCard(type, POINTS_ARR[i], i);
                pukeCards.add(pukeCard);
            }
        }
        // 单独处理大小王
        PukeCard sjoker = new PukeCard("", "SJOKER", 13);
        PukeCard bjoker = new PukeCard("", "BJOKER", 14);
        pukeCards.add(sjoker);
        pukeCards.add(bjoker);


        return pukeCards;
    }

    public static void main(String[] args) {
        List<PukeCard> pukeList = createPukeList();
        for (PukeCard pukeCard : pukeList) {
            System.out.println(pukeCard);
        }
        System.out.println(pukeList.size());

        ArrayList<PukeCard> p1 = new ArrayList<>();
        ArrayList<PukeCard> p2 = new ArrayList<>();
        ArrayList<PukeCard> p3 = new ArrayList<>();
        ArrayList<PukeCard> d1 = new ArrayList<>();

        drawPukeCard(pukeList,p1,p2,p3,d1);

        System.out.println("玩家1:"+p1);
        System.out.println("玩家2:"+p2);
        System.out.println("玩家3:"+p3);
        System.out.println("底牌:"+d1);

    }




}
